/**
 * 
 */
var Migrate = {
	/**
	 * 编辑数据库实体信息，选择对应lun
	 */
	edit : function() {
		common.dialog({
			obj : "#editMigrateLunDialog",
			type : "get",
			url : baseURL + "/migrate/edit",
			title : localeMsg.common.edit,
			width : 400,
			confirm : function() {
				if($("#editTargetForm").form('validate')!=true){
					return;
				}
				Migrate.save();
			}
		});
	},
	
	/**
	 * 保存
	 */
	save : function() {
		$("#editLunForm").ajaxSubmit({
			success : function(json) {
				// Save successfully and refresh the user list.
				if (json.result && json.result == "success") {
					common.showTip({
						title : localeMsg.common.prompt,
						text : localeMsg.common.saveSuccess,
						success : true,
						callback : function() {
							//Migrate.list();
						}
					});
				} else {
					common.showTip({title : localeMsg.common.warn, text : localeMsg.common.saveFailed});
				}
			}
		});
	},
	
	/**
	 * 展示数据库列表
	 */
	list : function() {
		$.ajax({
			type: "get",
			url: baseURL + "/migrate/list",
			success: function() {
				
			}
		});
	},
	
	/**
	 * 展示快速存储卷列表
	 */
	listCache : function() {
		
	},
	
	/**
	 * 卷迁移
	 */
	migrate : function(source) {
		var id = $(source).attr("value");
		var destPool = $("#destPool").val();
		var destImage = $("#destImage").val();
		var migrateUrl = baseURL + "/migrate/" + id;
		var param = {};
		if (destPool) param.destPool = destPool;
		if (destImage) param.destImage = destImage;
		$.ajax({
			type: "post",
			url: migrateUrl,
			data: param,
			success: function(json) {
				if (json && json.result == "success") {
					Migrate.move(source);
					common.showTip({text: "迁移成功", success: true});
				} else {
					common.showTip({text: "迁移失败", success: false});
				}
			}
		});
	},
	
	move : function(source) {
		$(source).removeAttr("style").removeClass("c_drag").addClass("c_drop")
				.appendTo("#tieredList .panel-body");
	},
	
	revert : function(source) {
		$(source).removeAttr("style");
	}
}